package com.polaris.live.ui.user_space

import android.os.Bundle
import com.blankj.utilcode.util.StringUtils
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.utils.getLongOrString
import com.polaris.live.viewmodel.UserSpaceViewModel
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.common.mvvm.base2.BaseVbActivity
import com.polaris.live.common.network.parseState
import com.polaris.live.common.util.ToastGravity
import com.polaris.live.constant.UserConst
import com.polaris.live.databinding.ActivitySealAccountBinding
import com.polaris.live.dialog.common.ConfirmCanalDetailDialog
import com.polaris.live.translation.R.string
import com.polaris.live.utils.route.RoutePath
import com.polaris.live.utils.route.Router

/**
 * 封号空间页
 *
 * @author Created by 长空 on 2023/11/16/004 14:01
 */
class SealAccountActivity :
    BaseVbActivity<UserSpaceViewModel, ActivitySealAccountBinding>() {

    private val longExtra: Long by lazy { intent.getLongOrString("userId", 0L) }
    private val otherId: Long by lazy { intent.getLongOrString("otherId", 0L) }

    override fun initView(savedInstanceState: Bundle?) {
        mBinding.tvId.text = getString(string.uid, longExtra.toString())
        if (UserConst.isManage()) { //是管理员
            mBinding.tvCancel.visibility = BottomPopupView.VISIBLE
        }
        mBinding.ivBack.setOnSingleClickListener {
            finish()
        }
        mBinding.tvCancel.setOnSingleClickListener {
            ConfirmCanalDetailDialog.show(
                this,
                mTitle = StringUtils.getString(string.cancel_the_ban),
                mDetail = StringUtils.getString(string.ban_tips),
                mConfirm = StringUtils.getString(string.sure),
                mCanal = StringUtils.getString(string.cancel),
                onConfirmCallback = {  mViewModel.managerUnBan(otherId) },
            )
        }

        mViewModel.managerUnBanLiveData.observe(this) { resultState ->
            parseState(resultState, {
                ToastGravity.showGravity(StringUtils.getString(string.un_ban_successfully))
                Router.builder(RoutePath.USER_SPACE_ACTIVITY)
                    .withInt("page", UserConst.From.USER_CARD)
                    .withLong("userId", otherId)
                    .navigation(this)
                finish()
            }, {
                ToastGravity.showGravity(it.errorMsg)
            })
        }
    }

}